package com.project.controller;

import com.project.bean.ProductBean;
import com.project.bean.SpeakBean;
import com.project.bean.UserBean;
import com.project.service.IProductService;
import com.project.service.ISpeakService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("speak")
public class SpeakController {
    @Autowired
    private ISpeakService speakService;
    @Autowired
    private IProductService productService;

    @RequestMapping("add")
    public String add(HttpServletRequest req, SpeakBean speak){
        UserBean user = (UserBean)req.getSession().getAttribute("loginUser");
        speak.setUserId(user.getId());
        speakService.add(speak);

        ProductBean product = productService.findById(speak.getProductId());
        req.setAttribute("product",product);
        return "/findById.html";
    }
}
